blob: 13a72b1214871d11a95cf99d2923412cd337ce65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, fetch }) => {
const id = params.id;
const [servicesRes, historyRes, statsRes, sslRes] = await Promise.all([
fetch(`http://localhost:8080/api/services`).catch(() => null),
fetch(`http://localhost:8080/api/services/${id}/history`).catch(() => null),
fetch(`http://localhost:8080/api/services/${id}/stats`).catch(() => null),
fetch(`http://localhost:8080/api/services/${id}/ssl`).catch(() => null)
]);
const services = servicesRes?.ok ? await servicesRes.json() : [];
const svc = services.find((s: any) => s.id === Number(id));
const historyJson = historyRes?.ok ? await historyRes.json() : [];
const history = Array.isArray(historyJson) ? historyJson : (historyJson.data ?? []);
const stats = statsRes?.ok ? await statsRes.json() : null;
const sslInfo = sslRes?.ok ? await sslRes.json() : null;
return {
service: svc ?? null,
history,
stats,
sslInfo
};
};
|